const mongoose = require('./db')
//维保基本信息
const MaintenanceBaseSchema = mongoose.Schema({
    plan_number:String,//计划编号
    plan_name:String,//计划名称
    device_name:String,//设备名称
    maintenance_cate:String,//维保类型
    cycle:String,//周期
    responsible_person:String,//责任人
    plan_start_time:Date,//计划开始时间
    plan_end_time:Date,//计划结束时间
    maintenance_illustrate:String,//维保说明
    maintenance_id:{//维保信息id
            type: mongoose.Types.ObjectId,
            ref: 'Maintenance'
    },
    repair_id:{ //用户id（外键）
        type: mongoose.Types.ObjectId,
        ref: 'userinfo'
    }
},{timestamps:true})

const MaintenanceBase = mongoose.model('MaintenanceBase',MaintenanceBaseSchema)
// MaintenanceBase.create(
// {
//     plan_number:'202303312125',
//     plan_name:'',
//     device_name:'空调',
//     maintenance_cate:'二级维保',
//     cycle:'1天',
//     responsible_person:'张三',
//     plan_start_time:Date.now(),
//     plan_end_time:Date.now(),
//     maintenance_illustrate:'闫鸿去修空调，振涛王牌维修员',
//     maintenance_id:undefined,
//     repair_id:'64252e1aa93ec1bf884de947',
// }
// )
//维保信息
const MaintenanceSchema = mongoose.Schema({
    responsible_person:{
        type: mongoose.Types.ObjectId,
        ref: 'userinfo'
    },//维保人
    active_time:Date,//维保时间
    maintenance_desc:String,//维保简介
    maintenance_expenses:Number,//维保费用
    image_path:Array//照片说明
},{timestamps:true})

const Maintenance = mongoose.model('Maintenance',MaintenanceSchema)

const InspectionSchema = mongoose.Schema({
    InspectionNumber:String,//计划编号
    InspectionName:String,//项目名称
    InspectionPosition:String,//巡检位置
    InspectionContent:String,//巡检内容
    Inspection_start_time:Date,//计划开始时间
    Inspection_end_time:Date,//计划结束时间
    repair_id:{ //用户id（外键）
        type: mongoose.Types.ObjectId,
        ref: 'userinfo'
    },
    isFinish:{
        type:Boolean,
        default:false
    }
})
const Inspection = mongoose.model('Inspection',InspectionSchema)
// Inspection.create({
//     InspectionNumber:'202304021315',
//     InspectionName:'8楼联查',
//     InspectionPosition:'8楼厕所',
//     InspectionContent:'厕所还是堵了！',
//     Inspection_start_time:Date.now(),
//     Inspection_end_time:Date.now()
// })
const equipmentSchema = mongoose.Schema({
    equipment_name:String,//设备名称
    qualified:Boolean,//设备状态
    parameter:String,//设备参数
    inspection_id:{ //计划id
        type:mongoose.Types.ObjectId,
        ref:'inspection'
    },
    location:String //位置
})
const Equipment = mongoose.model('equipment',equipmentSchema)
// Equipment.create({
//     equipment_name:'冰箱',
//     qualified:false,
//     parameter:'38',
//     inspection_id:'642910f9489868d93639d253',
//     location:'810'
// })
module.exports = {
    Maintenance,
    MaintenanceBase,
    Inspection,
    Equipment
}